package com.hsgene.order.listener;

import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.Message;
import com.hsgene.common.util.result.ApiResult;
import com.hsgene.common.util.result.NullObject;
import com.hsgene.order.service.OrderService;
import com.hsgene.util.mq.rocket.annotation.RocketMQListener;
import com.hsgene.util.mq.rocket.consumer.AbstractRocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;

/**
 * 订单半小时未支付提醒
 *
 * @author wangbing
 * @version 1.0
 * @date 2019/1/25 10:34
 * Copyright: Copyright (c) 2019
 */
@RocketMQListener(topic = "genetic_testing_order", tag = "genetic_testing_order_none_paid")
public class OrderCreationNonePaidListener extends AbstractRocketMQListener {

    private final static Logger LOGGER = LoggerFactory.getLogger(OrderCreationNonePaidListener.class);

    @Resource
    private OrderService orderService;

    @Override
    public Action messageHandler(Message message) {
        String orderNo = new String(message.getBody());
        ApiResult<NullObject> result = orderService.handleOrderNonePaidMsg(orderNo);
        if (result.isSucc()) {
            return Action.CommitMessage;
        }
        LOGGER.error("处理订单半小时未支付消息失败：" + result.getDesc());
        return Action.ReconsumeLater;
    }
}
